package com.zpp.gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

//这个类来管理游戏大厅的在线离线情况
@Component
public class OnlineUserManager {
    //哈希表表示当前用户在大厅的状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall = new ConcurrentHashMap<>();

    //这个哈希表表示当前用户在游戏房间的在线状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>();


    //进入游戏大厅
    public void enterGameHall(Integer userId, WebSocketSession session){
        gameHall.put(userId,session);
    }

    //退出游戏大厅
    public void exitGameHall(Integer userId) {
        gameHall.remove(userId);
    }

    //从游戏大厅找到键值对
    public WebSocketSession getFromGameHall(Integer userId) {
        return gameHall.get(userId);
    }

    public void enterGameRoom(Integer userId, WebSocketSession session){
        gameRoom.put(userId,session);
    }

    //退出游戏大厅
    public void exitGameRoom(Integer userId) {
        gameRoom.remove(userId);
    }

    //从游戏大厅找到键值对
    public WebSocketSession getFromGameRoom(Integer userId) {
        return gameRoom.get(userId);
    }

}
